#pragma once
#include <SDL.h>
#include <SDL_ttf.h>
#include <iostream>
#include <stdlib.h>
#include <string> 
#include <ctime>
#include <vector>
#include <time.h>
#include <cmath>
using namespace std;

#define MAX_DWARFS 5
#define MAX_SCOUTS 4  
#define MAX_YETIS 2
#define MAX_BEASTRIDERS 3
#define	MAX_DRAGONS 1
#define MAX_SLAYERS 1
#define MAX_ELFS 2
#define MAX_TRAPS 6
#define MAX_FLAGS 1
#define MAX_KNIGHTS 2
#define MAX_SORCERERS 2
#define MAX_MAGES 1 

struct TwoDimension
{
	int Xpos;
	int Ypos;

};
struct BoardGame
{
	//check what piece
	enum pieceCheck
	{
		SLAYER,
		SCOUT,
		DWARF,
		ELF,
		YETI,
		SORCERER,
		BEASTRIDER,
		KNIGHT,
		MAGE,
		DRAGON,
		FLAG,
		TRAP
	};
	
	//to assign what type of piece is it
	int piece;		
	//counter for frames
	int frameCounter;
	//check if its player or comp
	bool playerSide;
	//check if piece is revealed
	bool revealed;
	//check if there is an occupied space on board
	bool occupied;
	//check if piece can move
	bool canMove;
	//check if moving left
	bool movingLeft;
	//check if moving right
	bool movingRight;
	//check if attacking right
	bool attackRight;
	//check if attacking left
	bool attackLeft;
	//spaces able to move
	short moves;
	//for location of piece
	TwoDimension location;
};

class sdlManager
{
public:

	//used in main
	static sdlManager& getInstance() { static sdlManager pInstance; return pInstance; }

	//destructor
	~sdlManager(void);

	//draw
	void draw(SDL_Surface *);

	//release surfaces
	void shutdown();

	//updates frames
	void updateFrames();

	void loadImages();

	void setGrid();
	
	void outPutBoard();

	void getMousePosition(int x, int y);
	bool mouseInBounds();

	void getMouseClick(int xc, int yc);

	//for checking to set board
	bool settingBoard;

	//check if mouse button down
	bool buttonDownL;
	bool buttonDownR;

private:
	
	//constructor
	sdlManager(void);

	//for board
	BoardGame board[8][10];

	//for setting up pieces
	BoardGame settingPieces[13];

	//The font that's going to be used
	TTF_Font *font;

	// background
	SDL_Surface *background;
	SDL_Surface *World;

	
	//Marker
	SDL_Surface *Marker;
	TwoDimension markerXY;
	TwoDimension mouseXY;
	TwoDimension mouseXYClick;

	//Space Avialable
	SDL_Surface *MoveMarker;

	//sprites/piece
	SDL_Surface *beastRider;
	SDL_Surface *dragon;
	SDL_Surface *dwarf;
	SDL_Surface *elf;
	SDL_Surface *flag;
	SDL_Surface *knight;
	SDL_Surface *mage;
	SDL_Surface *scout;
	SDL_Surface *yeti;
	SDL_Surface *trap;
	SDL_Surface *slayer2;
	SDL_Surface *explosion;
	SDL_Surface *sorcerer;


	//data structure to holds pieces
	vector<BoardGame>pieces;

	//function to choosing your characters to put them on the screen
	void piecePlacement(SDL_Surface *screen);

	//function to select and do something with piece
	void pieceSelection(SDL_Surface *screen);

	

	//for images and drawing
	SDL_Surface *load_image( std::string filename );
	void apply_surface(int x, int y,SDL_Surface* source, SDL_Surface* destination, SDL_Rect *clip);
};